package genomemap.queries;

import genomemap.io.DataIO;
import genomemap.map.GeneMap;
import genomemap.map.ProbeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BestMaps extends Query {

    private Integer linkageGroup;

    private GeneMap bestGeneticMap;

    private ProbeMap bestPhysicalMap;

    private ProbeMap bestIntegratedMap;

    public BestMaps() {
    }

    public BestMaps(Integer linkageGroup, GeneMap bestGeneticMap, ProbeMap bestPhysicalMap,
            ProbeMap bestIntegratedMap) {
        this.linkageGroup = linkageGroup;
        this.bestGeneticMap = bestGeneticMap;
        this.bestPhysicalMap = bestPhysicalMap;
        this.bestIntegratedMap = bestIntegratedMap;
    }

    public GeneMap getBestGeneticMap() {
        return bestGeneticMap;
    }

    public ProbeMap getBestIntegratedMap() {
        return bestIntegratedMap;
    }

    public ProbeMap getBestPhysicalMap() {
        return bestPhysicalMap;
    }

    public Integer getLinkageGroup() {
        return linkageGroup;
    }

    @Override
    public Object getDataModel() {

        List<BestMaps> bestMapsList = new ArrayList<BestMaps>();

        // <editor-fold defaultstate="collapsed" desc="Load Best Maps">
        QueryRunner runner = QueryRunner.getInstance();
        List<Integer> linkageGroups = DataIO.getInstance().getLinkageGroups();

        for (Integer chromosome : linkageGroups) {

            bestMapsList.add(new BestMaps(
                    chromosome, new GeneMap(chromosome, Arrays.asList(
                    runner.getProperty("geneticmap.ch" + chromosome).split(","))),
                    new ProbeMap(chromosome, Arrays.asList(
                    runner.getProperty("physicalmap.ch" + chromosome).split(","))),
                    new ProbeMap(chromosome, Arrays.asList(
                    runner.getProperty("integratedmap.ch" + chromosome).split(",")))));
        }// </editor-fold>

        Map dataModel = new HashMap();

        List<GeneMap> bestGeneticMaps = new ArrayList<GeneMap>();
        for (BestMaps bestMaps : bestMapsList)
            bestGeneticMaps.add(bestMaps.getBestGeneticMap());
        dataModel.put("bestGeneticMaps", bestGeneticMaps);

        List<ProbeMap> bestPhysicalMaps = new ArrayList<ProbeMap>();
        for (BestMaps bestMaps : bestMapsList)
            bestPhysicalMaps.add(bestMaps.getBestPhysicalMap());
        dataModel.put("bestPhysicalMaps", bestPhysicalMaps);

        List<ProbeMap> bestIntegratedMaps = new ArrayList<ProbeMap>();
        for (BestMaps bestMaps : bestMapsList)
            bestIntegratedMaps.add(bestMaps.getBestIntegratedMap());
        dataModel.put("bestIntegratedMaps", bestIntegratedMaps);

        return dataModel;

    }

}
